home *** CD-ROM | disk | FTP | other *** search
- IDEAL
- LOCALS
- MODEL TPASCAL
- CODESEG
- PROC FindByte FAR _Data : DWORD, _Size : WORD, Num : BYTE
- PUBLIC FindByte
- ;function FindByte(var Data; Size : word; Num : byte) : word; external;
- mov al,[Num] ; Load search byte
- mov cx,[_Size] ; Load size
- les di,[_Data] ; Load address into es:di
- cld ; Scan forward
- repne scas [Num] ; Search for the sucker
- jne @@NotFound ; Not Found
- mov ax,[_Size] ; Load size
- sub ax,cx ; Subtract
- ret ; Done
- @@NotFound:
- xor ax,ax ; Return 0
- ret ; Exit
- ENDP FindByte
-
- PROC StrPos FAR _Data : DWORD, _Size : WORD, _St : DWORD
- ; function StrPos (var Data; Size : word; St : string) : word;
- PUBLIC StrPos
- push ds ; Save DS register
- cld ; Go forward
- lds si,[_St] ; Load ds:si with the String
- les di,[_Data] ; Load es:di with the array
- lodsb ; Load al with size of _St
- xor ah,ah ; Convert al to word ax
- mov bx,[_Size] ; Load size of array
- sub bx,ax ; Compare string sizes
- jb @@NotFound ; String larger so not found
- push bp ; Save bp
- inc bx ; stop at zero not after 0
- mov dx,di ; Offset into _Data
- mov bp,si ; Start of _St
- ; ax String size
- ; bx Comparisons left to make
- ; dx Offset into _Data
- ; bp Start of _St, bp no longer needed
- @@Compare:
- mov cx,ax ; Load string size
- mov di,dx ; Current location within _Data
- mov si,bp ; Start of _St
- repz cmpsb ; Compare the suckers
- jz @@Found ; Eureka!
- inc dx ; Next position
- dec bx ; One fell down, 99 bottles of beer...
- jnz @@Compare ; No more bottles of beer on the wall
- @@NotFound:
- pop bp ; Restore bp
- xor ax,ax ; Return 0
- jmp @@Done ; Get 'otta here
- @@Found:
- pop bp ; Restore bp
- mov ax,dx
- sub ax,[WORD _Data] ; Subtract starting offset
- inc ax ; Increment for base of 1 not 0
- @@Done:
- pop ds ; Restor DS register
- ret ; Done
- ENDP StrPos
- END
-